//
//  ZZOrderViewController.m
//  ZuZuBao
//
//  Created by Felix on 2024/4/10.
//

#import "ZZOrderViewController.h"
#import "ZZSegView.h"
#import "ZZOrderView.h"

@interface ZZOrderViewController ()<ZZSegViewDelegate>

@property (nonatomic, strong) ZZSegView * segView;
@property (nonatomic, strong) NSMutableArray * segArray;

@property (nonatomic, strong) ZZOrderView * orderView;
@property (nonatomic, strong) ZZOrderView * orderView1;
@property (nonatomic, strong) ZZOrderView * orderView2;
@property (nonatomic, strong) ZZOrderView * orderView3;

@end

@implementation ZZOrderViewController

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.segArray = [NSMutableArray arrayWithObjects:@"待收货", @"租用中", @"待归还", @"已完成", nil];
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"我的订单";
    
    [self createView];
    
}

- (void)createView {
    self.segView = [[ZZSegView alloc] initWithFrame:CGRectMake(0, kNavBarHeight, kScreenWidth, 40)];
    [self.segView setZZSegWithArray:self.segArray];
    [self.segView setSelectIndex:self.currentIndex];
    self.segView.delegate = self;
    [self.view addSubview:self.segView];
    
    self.orderView = [[ZZOrderView alloc] initWithFrame:CGRectMake(0, kNavBarHeight + 40, kScreenWidth, kScreenHeight - kNavBarHeight - 40)];
    [self.orderView setViewData:0];
    [self.view addSubview:self.orderView];
    
    self.orderView1 = [[ZZOrderView alloc] initWithFrame:CGRectMake(0, kNavBarHeight + 40, kScreenWidth, kScreenHeight - kNavBarHeight - 40)];
    [self.orderView1 setViewData:1];
    self.orderView1.hidden = YES;
    [self.view addSubview:self.orderView1];
    
    self.orderView2 = [[ZZOrderView alloc] initWithFrame:CGRectMake(0, kNavBarHeight + 40, kScreenWidth, kScreenHeight - kNavBarHeight - 40)];
    [self.orderView2 setViewData:2];
    self.orderView2.hidden = YES;
    [self.view addSubview:self.orderView2];
    
    self.orderView3 = [[ZZOrderView alloc] initWithFrame:CGRectMake(0, kNavBarHeight + 40, kScreenWidth, kScreenHeight - kNavBarHeight - 40)];
    [self.orderView3 setViewData:3];
    self.orderView3.hidden = YES;
    [self.view addSubview:self.orderView3];
    
    switch (self.currentIndex) {
        case 0:
            self.orderView.hidden = NO;
            self.orderView1.hidden = YES;
            self.orderView2.hidden = YES;
            self.orderView3.hidden = YES;
            break;
        case 1:
            self.orderView1.hidden = NO;
            self.orderView.hidden = YES;
            self.orderView2.hidden = YES;
            self.orderView3.hidden = YES;
            break;
        case 2:
            self.orderView2.hidden = NO;
            self.orderView.hidden = YES;
            self.orderView1.hidden = YES;
            self.orderView3.hidden = YES;
            break;
        case 3:
            self.orderView3.hidden = NO;
            self.orderView.hidden = YES;
            self.orderView1.hidden = YES;
            self.orderView2.hidden = YES;
            break;
            
        default:
            break;
    }
}

-(void)clickToSeg:(NSInteger)index
{
    self.currentIndex = index;
    switch (self.currentIndex) {
        case 0:
            self.orderView.hidden = NO;
            self.orderView1.hidden = YES;
            self.orderView2.hidden = YES;
            self.orderView3.hidden = YES;
            break;
        case 1:
            self.orderView1.hidden = NO;
            self.orderView.hidden = YES;
            self.orderView2.hidden = YES;
            self.orderView3.hidden = YES;
            break;
        case 2:
            self.orderView2.hidden = NO;
            self.orderView.hidden = YES;
            self.orderView1.hidden = YES;
            self.orderView3.hidden = YES;
            break;
        case 3:
            self.orderView3.hidden = NO;
            self.orderView.hidden = YES;
            self.orderView1.hidden = YES;
            self.orderView2.hidden = YES;
            break;
            
        default:
            break;
    }
}

@end
